from __future__ import annotations

from dataclasses import dataclass


@dataclass
class EarthworkVolume:
    excavation_m3: float
    backfill_m3: float
    note: str


def frustum_method(top_length: float, top_width: float, bottom_length: float, bottom_width: float, depth: float, backfill_ratio: float = 0.0) -> EarthworkVolume:
    """棱台法土方量：V = h/3 (A1 + A2 + sqrt(A1*A2))"""

    A1 = top_length * top_width
    A2 = bottom_length * bottom_width
    import math
    V = depth / 3.0 * (A1 + A2 + math.sqrt(max(0.0, A1 * A2)))
    return EarthworkVolume(excavation_m3=V, backfill_m3=V * backfill_ratio, note="棱台法")


